Skip to content

fix(analytics): keep timed events started before JS-mode storage load completes - #481

Draft
rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-257-react-native-261-timed-events-omit
Draft

rahul-mixpanel wants to merge 2 commits into
masterfrom
rahulraveendran-sdk-257-react-native-261-timed-events-omit

Conversation

@rahul-mixpanel

@rahul-mixpanel rahul-mixpanel commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related to #261 (Linear SDK-257).

In JavaScript mode, init() (and the MixpanelPersistent singleton on construction) re-read time events from storage asynchronously and then replaced the in-memory map with whatever was stored. A timeEvent() made while that read was in flight, e.g. right after an un-awaited init() (which the README sample shows), was wiped. The matching track() then went out without $duration.

The payload in #261 points to JS mode. It has none of the automatic properties native Android adds, such as $screen_dpi, $wifi, $app_version_string and $carrier. Its time is in milliseconds, which is what JS mode's track() sends.

Change

  • loadTimeEvents merges in-memory timers over the stored ones. In-memory timers are always at least as new as storage, because every update is persisted.
  • reset() clears in-memory timers explicitly, since it relied on the old overwrite.

No change to payload shape or public API. Native mode is untouched.

Cross-SDK parity

mixpanel-android, mixpanel-swift and mixpanel-js all attach $duration when an event started with timeEvent/time_event is tracked. This brings RN JS mode in line.

Tests

  • __tests__/main-time-event.test.js: un-awaited initialize() → timeEvent() → track() queues the event with $duration. It uses the real MixpanelPersistent with slow storage and fails on base.
  • MixpanelPersistent - time events: a timer started during a load survives it, and reset clears timers.
  • npx jest: 531 passed, 4 skipped.

Note (not changed here)

JS mode sends $duration in whole seconds (Math.round in eventElapsedTime), while Android, Swift and mixpanel-js send fractional seconds. This predates the PR. It's a possible parity follow-up, but it's a data change, so it needs a decision.

🤖 Generated with Claude Code

… completes

In JavaScript mode, `init()` (and the persistent singleton) re-read time
events from storage asynchronously and replaced the in-memory map with the
stored value. A `timeEvent()` call made while that read was in flight, e.g.
right after an un-awaited `init()`, was overwritten, so the later `track()`
was sent without `$duration`.

`loadTimeEvents` now merges in-memory timers over the stored ones, and
`reset()` clears the in-memory timers explicitly.

Related to #261

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 27, 2026

Copy link
Copy Markdown

SDK-257

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Reviews (2) · Last reviewed commit: "test(analytics): cover $duration for tim..." · Reviewed by Greptile

Related to #261

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant